/* 
* Authors: Stefan Bojarovski <bojarovski@gmail.com>
*		   Dmitry Lebedev <leeevd@gmail.com>
* June,	2011
*/

#include "max_clique.h"
#include "simple_bt.h"
#include "bron_kerbosch.h"

int performance_test() 
{
	clock_t start, end;
	int number_of_tests = 6;
	char file_name[MAX_FILENAME_LENGTH];
	char* root = "tests/test_";
	char* ext = ".dot";
	Graph inGraph;

	std::ofstream file(TEST_LOG);
	file<<"+-----------------+------------------------------------------------------------+"<< std::endl;
	file<<"| Number of nodes |                           Time                             |"<< std::endl;
	file<<"+-----------------+--------------------------+---------------------------------+"<< std::endl;
	file<<"| Graph  | Clique |   Simple Backtracking    |   Bron Kerbosch Backtracking    |"<< std::endl;
	file<<"+-----------------+--------------------------+---------------------------------+"<< std::endl;
	for (int i = 0; i <= number_of_tests; i++)
	{
		sprintf_s(file_name, MAX_FILENAME_LENGTH, "%s%d%s", root, i, ext);
		if(!graph_read(inGraph, file_name))
		{
			file<<" Error  |";
			file<<"          " << "Error" << "           |";
			file<<"              " << "Error" << "              |"<< std::endl;
			return 0;
		}
		else 
		{
			simple_bt simple_solver(&inGraph);
			start = clock();
			simple_solver.do_simple_BT();
			end = clock();
			file<<"|   "<< simple_solver.get_num_of_nodes() << "   |";
			file<< "   " << simple_solver.get_maxClique().size() << "   |";
			file<<"          " << (double)(end - start) / CLOCKS_PER_SEC << "           |";
			bron_kerbosch bron_kerbosch_solver(&inGraph);
			start = clock();
			bron_kerbosch_solver.do_bron_kerbosch_BT();
			end = clock();
			file<<"              " << (double)(end - start) / CLOCKS_PER_SEC << "              |"<< std::endl;
			file<<"+-----------------+--------------------------+---------------------------------+"<< std::endl;
			std::cout << file_name << " complete." << std::endl;
			file_name[0] = '\0';
		}
		inGraph.clear();
	}
	file.close();
	return 0;
}